package org.origin.ferret.center.configs;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.servers.Server;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置自定义 MySwagger 配置
 *
 * @author ferret
 * @version 2024-05-08
 */
@OpenAPIDefinition(
        info = @io.swagger.v3.oas.annotations.info.Info(
                title = "Your API Title",
                version = "v1",
                description = "Your API Description",
                termsOfService = "Your Terms Service Address",
                contact = @io.swagger.v3.oas.annotations.info.Contact(
                        name = "Your Name",
                        email = "your.email@example.com",
                        url = "http://your.website.com"
                ),
                license = @io.swagger.v3.oas.annotations.info.License(
                        name = "Your License Name",
                        url = "http://your.license.url.com"
                )
        ),
        security = {
                @io.swagger.v3.oas.annotations.security.SecurityRequirement(name = "oauth2")
        },
        servers = @Server(url = "http://localhost:${server.port:8080}")
)
@io.swagger.v3.oas.annotations.security.SecurityScheme(
        name = "oauth2",
        type = SecuritySchemeType.OAUTH2,
        flows = @io.swagger.v3.oas.annotations.security.OAuthFlows(
                password = @io.swagger.v3.oas.annotations.security.OAuthFlow(
                        tokenUrl = "${server.servlet.context-path:}/oauth2/token?resultType=3",
                        scopes = @io.swagger.v3.oas.annotations.security.OAuthScope(name = "all", description = "all"),
                        refreshUrl = "${server.servlet.context-path:}/oauth2/token"
                )
        )
)
@Configuration
@ConditionalOnProperty(prefix = "springdoc.api-docs", name = "enabled", havingValue = "true")
public class MySwaggerConfig {

//    @Bean
//    public SwaggerGrouping swaggerGrouping(DefaultListableBeanFactory beanFactory) {
//        return new SwaggerGrouping(beanFactory);
//    }
}
